#ifndef _MODBUS_RS485_H
#define _MODBUS_RS485_H

#include "sn_config.h"

#include "./uart/uart.h"
#include "./applications/app_can_master.h"

#define MODBUS_RX_LEN   16
#define MODBUS_TX_LEN   16

#define MODBUS_CMD_READ_MSG 0x03
#define MODBUS_CMD_SET_PARAM 0x06
#define MODBUS_CMD_SET_POWER 0x05

#define MODBUS_RX485_CTL_Pin   

#define  MODBUS_RX485_CTL_GPIO  		 	GPIO0
#define  MODBUS_RX485_CTL_GPIO_Pin  	    GPIO_Pin_5


struct modbus_rs485_t
{
    struct uart_dev_t *uartDev;
    uint8_t rcvFinish ;//开始接收
    uint8_t Frameflag ;// 1 正在处理一帧数据 0 处理完成 可以接收数据
    uint8_t timerRun;//启动定时器
    uint8_t rcvTimeoutCnt;//接收超时，完成一帧
    uint8_t  rcvBuf[MODBUS_RX_LEN];
    uint16_t rcvCnt;
    uint8_t txBuf[MODBUS_TX_LEN];
    uint16_t txCnt;
    
    unsigned int (*crc16_func)(struct modbus_rs485_t *dev,unsigned char *puchMsg, unsigned char usDataLen);
    void (*timer_start)(struct modbus_rs485_t *dev);
    void (*timer_stop)(struct modbus_rs485_t *dev);
    void (*send_buf)(struct modbus_rs485_t *dev);
};

void modbus_init(void);

void modbus_loop_func(void);
#endif //



